package com.njupt.Array;

import java.util.*;

import java.util.*;

import java.util.*;

import java.lang.ref.WeakReference;

public class Main {
    public static void main(String[] args) throws InterruptedException {

        Object myObject = new Object();

        // 创建弱引用
        WeakReference<Object> weakRef = new WeakReference<>(myObject);

        System.out.println("GC前，弱引用获取的对象: " + weakRef.get());

        // 断开强引用
        //myObject = null;

        // 强制触发垃圾回收
        //ThreadLocal
        System.gc();

        Thread.sleep(1000);
        System.out.println("GC后，弱引用获取的对象: " + weakRef);

        System.out.println("强引用对象: " + myObject);
    }

}